package ch.kerbtier.malurus.renderers;

import java.util.ArrayList;
import java.util.List;

import ch.kerbtier.malurus.Renderer;
import ch.kerbtier.malurus.RenderProvider;

public class ChainRenderProvider implements RenderProvider {

	private List<RenderProvider> renderers = new ArrayList<RenderProvider>();


	public void add(RenderProvider renderer) {
		renderers.add(renderer);
	}

	public Renderer getRenderer(String component, String realisation) {
		for (RenderProvider r : renderers) {
			Renderer renderer = r.getRenderer(component, realisation);
			if (r != null) {
				return renderer;
			}
		}
		// if no renderer with realisation, take default renderer
		for (RenderProvider r : renderers) {
			Renderer renderer = r.getRenderer(component, null);
			if (r != null) {
				return renderer;
			}
		}
		return null;
	}

}
